#include "inodeblock.h"
#include <iostream>
#include "lib/e7convert.h"


InodeBlock::InodeBlock(FILE* device, unsigned long offset) : Block(device, offset)
{
    inodes = new std::vector<Inode*>();
    inodeBlock = new inode_block_t();
    read(inodeBlock, sizeof(inode_block_t));

    //getchars(inodeBlock->inodes->offset, 2,14 );
    //cout << (char*) inodeBlock->inodes[1][1] << endl;

    loadInodes();

}

InodeBlock::~InodeBlock()
{
    for(int i=0; i<inodes->size(); i++)
    {
        delete (*inodes)[i];
    }

    delete inodes;
    delete inodeBlock;
}

void InodeBlock::loadInodes()
{
    for(int i = 0; i < INODELIST_SIZE; i++)
    {
    	//cout << "Load Inode at: " << offset + INODE_SIZE * i << endl;
        inodes->push_back(new Inode(device, offset + INODE_SIZE * i));
    }
}


//Inode * InodeBlock::getInodes() {
//    Inode * inodes = new Inode[INODELIST_SIZE];
//    for(int i = 0; i < INODELIST_SIZE; i++) {
//        inodes[i] = new Inode(device, offset + INODE_SIZE * i);
//    }
//}

void InodeBlock::print()
{
    for(int i = 0; i < inodes->size(); i++)
    {
        (*inodes)[i]->print();
    }
}



